package vn.edu.saigontech.ncms.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

import vn.edu.saigontech.ncms.model.system.Shift;
import vn.edu.saigontech.ncms.web.offering.report.ShiftMap;

public class CollectionUtil {
	
	public static Collection<String> create(String[] values) {
		return Arrays.asList(values);
	}
	
	public static Map<Date, ShiftMap> createScheduleMap(Collection<Date> dates) {
		Map<Date, ShiftMap> scheduleMap = new HashMap<Date, ShiftMap>();
		for(Date date : dates) {
			scheduleMap.put(date, createShiftMap());
		}
		return scheduleMap;
	}
	
	public static ShiftMap createShiftMap() {
		ShiftMap shiftMap = new ShiftMap();
		shiftMap.put(Shift.SHIFT_1, 0);
		shiftMap.put(Shift.SHIFT_2, 0);
		shiftMap.put(Shift.SHIFT_3, 0);
		shiftMap.put(Shift.SHIFT_4, 0);
		return shiftMap;
	}
	
	@SuppressWarnings("unchecked")
	public static String toString(Collection values, String property, String splitter) {
		List list = new ArrayList();
		try {
			for(Object each : values) {
					list.add(BeanUtils.getProperty(each, property));
			}
		} 
		catch (Exception ex) { 
			ex.printStackTrace(); 	
		}
		return toString(list, splitter);
	}
	
	@SuppressWarnings("unchecked")
	public static String toString(Collection values, String splitter) {
		String string = values.toString().replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(", ", splitter);
		return string;
	}
}